<?php
namespace Admin\Form;
use Zend\Form\Form;

class EditForm extends Form{
	public function __construct($name = ''){
		parent::__construct('EditFrom');
	}

	public function uploadFiles($files = array(), $filePaths = ''){
		// cần kiểm tra xem đã tồn tại thư mục hay chưa
		if(!is_dir($filePaths)){
			// nếu chưa có thư mục

		}			
		$totalFiles = count($files);
		$fileName = array();
		$fileName[0] = 0;
		if(count($files)!=0 && $filePaths!=''){
			$uploadObj = new \Zend\File\Transfer\Adapter\Http();
			$uploadObj->setDestination($filePaths);
			$counter = 0;
			foreach ($files as $key => $value) {
				if($uploadObj->receive($key) && $value['name']!=''){
				  	$counter++;
					$fileName[$counter] = $value['name'];
				}
			}
		}
		// kiểm tra thành công hay chưa
		if($counter == $totalFiles)
			return true;
		return false;
	}

	public function deleteFiles($files = array(), $filePaths = ''){
		$totalFiles = count($files);
		$counter = 0;
		foreach ($files as $file) {
			$temp = $filePaths.'/'.$file;
			if(file_exists($temp) && $file!= NULL){
				if(unlink($temp)){
					$counter++;
				}
			}
		}
		if($counter == $totalFiles)
			return true;
		return false;
	}	

}